const tagViews = {
    state: {
        visibleViews: [],
        cacheViews: []
    },
    mutations: {
        ADD_TAG_VIEW(state, tagView) {
            if (!state.visibleViews.find(o => o.name === tagView.name)) {
                state.visibleViews.push(tagView)
                if (!tagView.meta.noCache) {
                    state.cacheViews.push(tagView.name)
                }
            }
        },
        DELETE_TAG_VIEW(state,tagView){
            if(tagView.meta.noClose) return false
            let index = state.visibleViews.findIndex(o => o.name === tagView.name)
            let cacheIndex = state.visibleViews.findIndex(o => o === tagView.name)
            if(index !== -1){
                state.visibleViews.splice(index, 1)
            } 
            if(cacheIndex !== -1){
                state.cacheViews.splice(cacheIndex, 1)
            }
        }
    },
    actions: {
        addTagView({commit},route){
            commit('ADD_TAG_VIEW',route)
        },
        deleteTagView({commit},route){
            commit('DELETE_TAG_VIEW',route)
        }
    }
}

export default tagViews